Sub ShowKeys()
Dim cat1 As ADOX.Catalog
Dim tbl1 As ADOX.Table
Dim key1 As ADOX.Key
Dim maxlen As Integer

'Specify database engine and data source
Set cat1 = New ADOX.Catalog
cat1.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" _
     & "Data Source=C:\LunarSociety\OLS1.mdb"

'Find longest key name
maxlen = 8
For Each tbl1 In cat1.Tables
    For Each key1 In cat1.Tables(tbl1.Name).Keys
        If maxlen < Len(key1.Name) Then maxlen = Len(key1.Name)
    Next key1
Next tbl1
maxlen = maxlen + 1

'Display key report heading
Debug.Print "Key Names and Types for OLS1.mdb"
Debug.Print "Table Name"
Debug.Print String(5, " ") & "Key Name" & _
    String(maxlen - 8, " ") & "Key Type"
   
'Examine all tables and display key information
For Each tbl1 In cat1.Tables
    If tbl1.Type = "table" And _
        Left(tbl1.Name, 4) <> "~TMP" Then
        Debug.Print tbl1.Name
        For Each key1 In tbl1.Keys
            Debug.Print String(5, " ") & key1.Name & _
                String(maxlen - Len(key1.Name), " ") & _
                KeyType(key1.Type)
        Next key1
    End If
 Next tbl1

 'Clean up before exiting
 Set cat1 = Nothing

End Sub
